package com.sdlg.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdlg.pojo.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuMapper extends BaseMapper<Menu> {
    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_member WHERE id=#{uid}))AND parent_menuId is null")
    public List<Menu> member_getParentMenu(@Param("uid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_member WHERE id=#{uid}))AND parent_menuId =#{pid}")
    public List<Menu> member_getChildMenu(@Param("uid") Integer uid,@Param("pid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_lry WHERE id=#{uid}))AND parent_menuId is null")
    public List<Menu> lry_getParentMenu(@Param("uid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_lry WHERE id=#{uid}))AND parent_menuId =#{pid}")
    public List<Menu> lry_getChildMenu(@Param("uid") Integer uid,@Param("pid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_root WHERE id=#{uid}))AND parent_menuId is null")
    public List<Menu> root_getParentMenu(@Param("uid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_root WHERE id=#{uid}))AND parent_menuId =#{pid}")
    public List<Menu> root_getChildMenu(@Param("uid") Integer uid,@Param("pid") Integer id);

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_root WHERE id=2))AND parent_menuId is noy null")
    public List<Menu> lrygetMenu();

    @Select("SELECT * FROM t_menu WHERE id in(SELECT menu_id FROM t_role_menu WHERE role_id =" +
            "(SELECT role_id FROM t_root WHERE id=3))AND parent_menuId is noy null")
    public List<Menu> membergetMenu();

}
